package com.my.house.vo;

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.AssertTrue;
import lombok.Data;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

/**
 * 日期范围请求实体
 * @author yangll
 */
@Data
public class DateRangeReqVO {
    /**
     * 开始日期
     */
    @NotNull
    private LocalDate startDate;
    /**
     * 截止日期
     */
    @NotNull
    private LocalDate endDate;

    @AssertTrue(message = "结束时间不能在开始时间之前")
    private boolean isEndDateAfterStartDate() {
        return endDate.isAfter(startDate);
    }

    @AssertTrue(message = "开始结束时间的天数差不能超过31天")
    private boolean isDateRangeWithin31Days() {
        return ChronoUnit.DAYS.between(startDate, endDate) <= 31;
    }
}